package pl.donajski.magisterka;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;

public class FileNodeLoader extends FileLoader {
	/**
	 * Creates FileNodeLoader instance
	 * @param fileName path to file with node definitions (file format
	 * has to match format specified in specification file)
	 * @throws FileNotFoundException 
	 */
	public FileNodeLoader(String fileName) throws FileNotFoundException {
		super(fileName);
	}

	public List<Node> load() {
		List<Node> nodeList = new ArrayList<Node>();
		int count = Integer.parseInt(this.next());
		for(int i = 0 ; i < count; ++i) {
			nodeList.add(createNode(i));
		}
		
		return nodeList;
	}
	
	private Node createNode(int idx) {
		int capacityModuleOpex 	= 0,
			capacityModuleSize 	= 0,
			processingOpex		= 0,
			processingRateMax	= 0;
			
		//skip node index
		this.next();
		capacityModuleOpex 	= Integer.parseInt(this.next());
		capacityModuleSize 	= Integer.parseInt(this.next());
		processingOpex		= Integer.parseInt(this.next());
		processingRateMax	= Integer.parseInt(this.next());
		assert(capacityModuleOpex > 0 && capacityModuleSize > 0 && processingOpex > 0 && processingRateMax >= 0);
		return new Node(idx,
						capacityModuleOpex,
						capacityModuleSize,
						processingOpex,
						processingRateMax);
	}

}
